package models

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

type User struct {
	Id      int    `json:"id" gorm:"type:int"`
	Name    string `json:"name" gorm:"type:varchar(30)"`
	Tel     string `json:"tel" gorm:"type:varchar(30)"`
	Email   string `json:"email" gorm:"type:varchar(30)"`
	Info    int    `json:"info" gorm:"type:int"`
	GetTime string `json:"get_time" gorm:"type:datetime"`
}

var (
	DB  *gorm.DB
	err error
)

func init() {
	dsn := "root:root@tcp(127.0.0.1:3306)/day12"
	DB, err = gorm.Open(mysql.Open(dsn))
	if err != nil {
		fmt.Println("数据库连接失败")
		return
	}
	fmt.Println("数据库连接成功")
	err = DB.AutoMigrate(&User{})
	if err != nil {
		fmt.Println("迁移失败")
		return
	}
	fmt.Println("迁移成功")
}
